package com.atguigu.myssm.trans;


import com.atguigu.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @ClassName: TransactionManager
 * @Description:
 * @Author: wty
 * @Date: 2022/12/8
 */

public class TransactionManager {

    // 开启事务
    public static void beginTrans() throws SQLException {
        Connection connection = DruidUtils.getConnection();
        connection.setAutoCommit(false);
    }

    // 提交事务
    public static void commit() throws SQLException {
        Connection connection = DruidUtils.getConnection();
        connection.commit();

        // 关闭连接
        DruidUtils.closeConnection();
    }

    // 回滚事务
    public static void rollback() throws SQLException {
        Connection connection = DruidUtils.getConnection();
        connection.rollback();

        // 关闭连接
        DruidUtils.closeConnection();
    }


}
